
package com.jsu.collegestudentadmissionsystem.service.Impl;

import com.jsu.collegestudentadmissionsystem.dao.AdministratorDao;
import com.jsu.collegestudentadmissionsystem.pojo.vo.*;
import com.jsu.collegestudentadmissionsystem.service.AdministratorService;
import com.jsu.collegestudentadmissionsystem.utils.AcquireStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Scanner;

@Service
public class AdministratorServiceImpl implements AdministratorService {
    @Autowired
    AdministratorDao administratorDao;

    @Autowired
    AcquireStatus acquireStatus;

//    Scanner sc = new Scanner(System.in);

    ///对专业信息进行增删改查(major_info)
    @Override
    public void insertMajorInformation(Integer s, String s1, String s2) {
        administratorDao.insertMajorInformation(s, s1, s2);
    }

    @Override
    public void deleteMajorInformation(Integer s) {
        administratorDao.deleteMajorInformation(s);
    }

    @Override
    public void alterMajorInformation(Integer s, String s1, String s2) {
        administratorDao.alterMajorInformation(s, s1, s2);
    }

    @Override
    public void queryMajorInformation() {
        List<MajorInformation> majorInformationList = administratorDao.queryMajorInformation();
        String s;
        for(int i=0;i<majorInformationList.size();i++){
            Integer majorId = majorInformationList.get(i).getMajorId();
            String majorName = majorInformationList.get(i).getMajorName();
            String majorCode = majorInformationList.get(i).getMajorCode();

            s = majorId+"----"+majorCode+"----"+majorName+'\n';
            System.out.println(s);
        }
    }


    ///对中学院校信息进行增删改查(middle_school_info)
    @Override
    public void insertMiddleSchoolInformation(Integer middle_school_id, String middle_school_name) {
        administratorDao.insertMiddleSchoolInformation(middle_school_id, middle_school_name);
    }

    @Override
    public void deleteMiddleSchoolInformation(Integer middle_school_id) {
        administratorDao.deleteMiddleSchoolInformation(middle_school_id);
    }

    @Override
    public void alterMiddleSchoolInformation(Integer id, Integer middle_school_id, String middle_school_name) {
        administratorDao.alterMiddleSchoolInformation(id, middle_school_id, middle_school_name);
    }

    @Override
    public void queryMiddleSchoolInformation() {
        List<MiddleSchoolInformation> middleSchoolInformationList = administratorDao.queryMiddleSchoolInformation();
        String s;
        for(int i=0;i<middleSchoolInformationList.size();i++){
            Integer middle_school_id = middleSchoolInformationList.get(i).getMiddleSchoolId();
            String middle_school_name = middleSchoolInformationList.get(i).getMiddleSchoolName();

            s = middle_school_id+"----"+middle_school_name+'\n';
            System.out.println(s);
        }
    }


    ///对高校信息进行增删改查(college_major_info)
    @Override
    public void insertCollegeMajorInformation(Integer college_major_id, Integer college_name, Integer major_name, Integer admission_batch_name, Integer admission_quantity) {
        administratorDao.insertCollegeMajorInformation(college_major_id, college_name, major_name, admission_batch_name, admission_quantity);
    }

    @Override
    public void deleteCollegeMajorInformation(Integer college_major_id) {
        administratorDao.deleteCollegeMajorInformation(college_major_id);
    }

    @Override
    public void alterCollegeMajorInformation(Integer college_major_id, Integer college_name, Integer major_name, Integer admission_batch_name, Integer admission_quantity) {
        administratorDao.alterCollegeMajorInformation(college_major_id, college_name, major_name, admission_batch_name, admission_quantity);
    }

    @Override
    public void queryCollegeMajorInformation() {
        List<CollegeMajorInformation> collegeMajorInformationList = administratorDao.queryCollegeMajorInformation();
        String s;
        for(int i=0;i<collegeMajorInformationList.size();i++){
            Integer college_major_id = collegeMajorInformationList.get(i).getCollegeMajorId();
            String college_name = collegeMajorInformationList.get(i).getCollegeName();
            String major_name = collegeMajorInformationList.get(i).getMajorName();
            String admission_batch_name = collegeMajorInformationList.get(i).getAdmissionBatchName();
            Integer admission_quantity = collegeMajorInformationList.get(i).getAdmissionQuantity();

            s = college_major_id+"----"+college_name+"----"+major_name+"----"+admission_batch_name+"----"+admission_quantity+'\n';
            System.out.println(s);
        }
    }


    ///对考生成绩信息进行增删改查(score_info)
    @Override
    public void insertScoreInformation() {
        System.out.println("请输入：\n" +
                "学生ID 主科一   主科二   主科三  选科一   选科二  选科三\n");
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        str=str.replaceAll(" +"," ");
        String [] mid = str.split(" ");
        Integer totalScore = Integer.parseInt(mid[1]) +Integer.parseInt(mid[2]) + Integer.parseInt(mid[3]) + Integer.parseInt(mid[4]) + Integer.parseInt(mid[5]) +Integer.parseInt(mid[6]);
        System.out.println(totalScore);
        administratorDao.insertScoreInformation(
                Integer.valueOf(mid[0]), Float.parseFloat(mid[1]),
                Float.parseFloat(mid[2]), Float.parseFloat(mid[3]),
                Float.parseFloat(mid[4]),  Float.parseFloat(mid[5]),
                Float.parseFloat(mid[6]), (int)totalScore);
    }

    @Override
    public void deleteScoreInformation(Integer score_id) {
        administratorDao.deleteScoreInformation(score_id);
    }

    @Override
    public void alterScoreInformation(Integer score_id, Integer student_id, float main_subject_score_one, float main_subject_score_two, float main_subject_score_three, float subject_score_one, float subject_score_two, float subject_score_three, float total_score) {
        administratorDao.alterScoreInformation(score_id, student_id, main_subject_score_one, main_subject_score_two, main_subject_score_three, subject_score_one,  subject_score_two, subject_score_three, total_score);
    }

    @Override
    public void queryScoreInformation() {
        List<ScoreInformation> scoreInformationList = administratorDao.queryScoreInformation();
        String s;
        for(int i=0;i<scoreInformationList.size();i++){
            Integer score_id = scoreInformationList.get(i).getScoreId();
            Integer student_id = scoreInformationList.get(i).getStudentId();
            float main_subject_score_one = scoreInformationList.get(i).getMainSubjectScoreOne();
            float main_subject_score_two = scoreInformationList.get(i).getMainSubjectScoreTwo();
            float main_subject_score_three = scoreInformationList.get(i).getMainSubjectScoreThree();
            float subject_score_one = scoreInformationList.get(i).getSubjectScoreOne();
            float subject_score_two = scoreInformationList.get(i).getSubjectScoreTwo();
            float subject_score_three = scoreInformationList.get(i).getSubjectScoreThree();
            float total_score = scoreInformationList.get(i).getTotalScore();

            s = score_id+"----"+student_id+"----"+main_subject_score_one+"----"+main_subject_score_two+"----"+main_subject_score_three+"----"+subject_score_one+"----"+subject_score_two+"----"+subject_score_three+"----"+total_score+'\n';
            System.out.println(s);
        }
    }


    ///对考生信息进行修改(student_info)
    @Override

    public void updateStatus() {
        System.out.println("1、录取前  2、录取中  3、录取后\n" +
                "请选择输入数字来选择状态");
        Scanner sc = new Scanner(System.in);
        Integer status = sc.nextInt();
//        sc.close();
        acquireStatus.setStatus(status);
    }




    public void insertStudentInformation() {
        //  还有啥问题吗 有  为什么写在这  这里是service层 负责业务逻辑的 业务逻辑全写这里面 最开始那个给参数的地方要么不要再controller里面写 要么在controller上一层写
        System.out.println("请输入学生Id 学生姓名 学生中学 班级");
        Scanner sc = new Scanner(System.in);
        String userInput = sc.nextLine();
////        sc.close();
        userInput=userInput.replaceAll(" +"," ");
        String[] userInputArr = userInput.split(" ");
        MiddleSchoolInformation schoolInformation = administratorDao.queryMiddleSchoolByName(userInputArr[2]);  //  你这什么命名方式
        if (schoolInformation == null) {
            System.out.println("错误: 输入的目标院校不存在");
            return;
        }
        administratorDao.insertStudentInformation(Integer.valueOf(userInputArr[0]), userInputArr[1], schoolInformation.getMiddleSchoolId(), Integer.valueOf(userInputArr[3]));
    }

    public void searchStudentInformation() {
        System.out.println(administratorDao.searchStudentInformation());
    }

    @Override
    public void searchCollegeInformation() {
//        System.out.println(administratorDao.searchCollegeInformation());
        List<CollegeInformation> collegeInformations = administratorDao.searchCollegeInformation();
        collegeInformations.forEach(System.out::println);
    }


    ///对院校信息进行修改(college_info)
    public void insertCollegeInformation(){
        System.out.println("请输入:\n" +
                "学校编号（注：不可重复）     学校名字      学校地址\n");
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
//        sc.close();
        str=str.replaceAll(" +"," ");
        String [] mid = str.split(" ");
        System.out.println(mid[0]);
        System.out.println(mid[1]);
        System.out.println(mid[2]);
        administratorDao.insertCollegeInformation( mid[0],mid[1],mid[2]);
    }




}

